package cz.acies.genea.ui.svg;

import com.google.gson.JsonObject;

public class G2Line extends G2Object
{
	private static final long serialVersionUID = 5373622861887996418L;
	
	public double x1;
	public double y1;
	public double x2; 
	public double y2;
	
	public G2Line() {
		this(0, 0, 0, 0);
	}

	public G2Line(G2Point p1, G2Point p2) {
		this(0, 0, 0, 0);
		computeShape(p1, p2);
	}

	public G2Line(double x1, double y1, double x2, double y2) {
		this.x1 = x1;
		this.y1 = y1;
		this.x2 = x2;
		this.y2 = y2;
	}

	// -----  -----------------------------------------------------------------

	private void computeShape(G2Point p1, G2Point p2) {
		this.x1 = p1.x;
		this.y1 = p1.y;
		this.x2 = p2.x;
		this.y2 = p2.y;
	}

	// -----  -----------------------------------------------------------------

	@Override
	public JsonObject toJSON(JsonObject element) {
		element = super.toJSON(element);
		JsonObject draw = (JsonObject) element.get("draw");
		String path = "M"+x1+","+y1+"L"+x2+","+y2;
		draw.addProperty("path", path);		
		return element;
	}

	// -----  -----------------------------------------------------------------
	
	@Override
	public String getType() {
		return "path";
	}

	// -----  -----------------------------------------------------------------
	
	public String toString() {
		return "G2Line[x = " + x1 + ", y = " + y1 + ", width = " + x2 + ", height = " + y2 + "]"; 
	}

}
